package com.qztech.sdk.ui.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qztech.sdk.R;
import com.qztech.sdk.model.Data;

import java.util.List;


/**
 * Created by zhanghb on 2018/10/31.
 */

public class FileAdapter extends RecyclerView.Adapter {

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    private OnItemClickListener mOnItemClickListener;

    private List<Data> mUserProfiles;


    public FileAdapter(List<Data> userProfiles) {
        mUserProfiles = userProfiles;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_file_list, viewGroup, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        MyViewHolder holder = (MyViewHolder) viewHolder;
        Data data = mUserProfiles.get(i);
        holder.tvDate.setText(data.getSubTitle() + "");
        holder.tvFileName.setText(data.getTitle() + "");
        holder.tvNum.setText((i + 1) + "");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onItemClick(i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mUserProfiles.size();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tvNum;
        TextView tvDate;
        TextView tvFileName;

        public MyViewHolder(View itemView) {
            super(itemView);
            tvNum = itemView.findViewById(R.id.tvNumber);
            tvDate = itemView.findViewById(R.id.tvDate);
            tvFileName = itemView.findViewById(R.id.tvFileName);
        }
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
}
